package com.example.demo.controller;


import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.dao.UserMapper;
import com.example.demo.model.User;
import com.example.demo.vo.resp.UserListRespVo;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author java
 * @since 2020-08-31
 */
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Resource
	UserMapper userMapper;
	
	
	@GetMapping("/get")
	public Page<UserListRespVo> getUuser() {
		QueryWrapper<User> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("id", 1);
		Page<User> page = new Page<>(1, 10);
		Page<User> list = userMapper.selectPage(page, queryWrapper);
		List<User> records = list.getRecords();
		// po -> vo
        List<UserListRespVo> collect = records.stream().map(po -> {
        	UserListRespVo vo = new UserListRespVo();
            BeanUtils.copyProperties(po, vo);
            return vo;
        }).collect(Collectors.toList());
        
        Page<UserListRespVo> pageList = new Page<>();
        
        BeanUtils.copyProperties(list, pageList);
        pageList.setRecords(collect);
		System.out.println(JSONArray.toJSONString(list));
		return pageList;
	}

}

